<template>
	<view class=""></view>
</template>

<script>
	//道闸模式
	export default {
		data() {
			return {
				cddxtype: false,
				ChargeUserz: [],
				ChargeUser: [],
			};
		},
		watch: {
			ChargeCar: {
				handler(val, oldval) {
					this.init14();
				},
				deep: true,
			},
		},
		onShow() {},
		computed: {},
		methods: {
			async btntap14tdtap(td) {
				if (this.ChargeCar.type != 14 || !this.ChargeCar.gtel) {
					return true;
				}

				if (!this.type14init) {
					this.ChargeUser = await this.$store.dispatch("request/getRequest", {
						url: "/ChargeUser",
					});
				}
				console.log(this.btntext, "this.btntext ");
				this.$nextTick(() => {
					if (this.i == 0 && this.btntext == "打开地锁") {
						this.i++;
						this.$refs.cdxz14.init();
					} else if (this.i == 0 && this.btntext == "开始充电") {
						this.i++;
						this.$refs.zmodal.close();
					}
					console.log(this.btntext, "this.btntext ");
				});
				if (this.ChargeCar[`glzt${td}`] != "0") {
					let ChargeUser = this.ChargeUser.find((e) => {
						return (
							e.gtel == this.ChargeCar.gtel && e.b_end != "1" && e.td == td
						);
					});
					if (ChargeUser) {
						if (ChargeUser.sjcds) {
							this.umodaldata = {
								show: true,
								content: "您有订单已经开始充电，请结束当前订单后再充。",
								showTitle: false,
							};
							// this.btnloading = true;
							return Promise.reject();
						} else {
							this.btntext = "开始充电";
							return true;
						}
					} else {
						this.$refs.zmodal.init({
							content: "此通道已被占用，请更换通道或待地锁完全升起后重新扫码。",
						});
						this.btnloading = true;
						return Promise.reject();
					}
				} else {
					if (this.btntext == "开始充电") {
						this.$refs.zmodal.init({
							content: "您有订单已经开始充电，请结束当前订单后再充。",
						});
						// this.btnloading = true;
						return Promise.reject();
					}
					this.btntext = "打开地锁";

					return true;
				}
			},
			async init14modal() {
				this.ChargeUserz = await this.$store.dispatch("request/getRequest", {
					url: "/ChargeUser",
				});
				this.ChargeUser = this.ChargeUserz.filter((e) => {
					return (
						e.b_end == 0 &&
						!(e.gtel == this.query.gtel && e.td == this.query.td)
					);
				});
				let ChargeUserzw = this.ChargeUser.filter((e) => {
					return e.b_cd == 0;
				});
				for (let i = 0; i < ChargeUserzw.length; i++) {
					let item = ChargeUserzw[i];
					console.log(item, "item");
					let ChargeUser = await this.$store.dispatch("request/getRequest", {
						url: "/ChargeCarSys",
						data: {
							gtel: item.gtel,
						},
					});
					if (ChargeUser.length == 1 && ChargeUser[0].type == 14) {
						this.$refs.zmodal.init({
							content: "系统检测到您有未关闭的占位订单，请关闭后重新扫码。",
							confirm: () => {
								this.$z.back()
							},
						});
						this.btnloading = true;
						return;
					}
				}

				let ChargeUsercd = this.ChargeUser.filter((e) => {
					return e.b_cd == 1;
				});
				for (let i = 0; i < ChargeUsercd.length; i++) {
					let item = ChargeUsercd[i];
					let ChargeUser = await this.$store.dispatch("request/getRequest", {
						url: "/ChargeCarSys",
						data: {
							gtel: item.gtel,
						},
					});
					if (ChargeUser.length == 1 && ChargeUser[0].type == 14) {
						this.$refs.zmodal.init({
							showcancel: true,
							content: "系统检测到您正在进行的充电订单，是否开启新的订单。",
							confirm: () => {},
							cancel: () => {
								uni.navigateTo({
									url: "/pages/ChargeUser/ChargeUser",
								});
							},
						});
						return;
					}
				}
				// let ChargeUserdq = this.ChargeUserz.find((e) => {
				// 	return (
				// 		e.b_end == 0 && e.gtel == this.query.gtel && e.td == this.query.td
				// 	);
				// });

				this.zftext = "去支付";
				// if (ChargeUserdq) {
				// 	// this.$refs.cdxz14.init();
				// 	// this.cddxtype = true;
				// 	this.zftext = "去支付";
				// } else {
				// 	// this.zftext = "打开地锁";
				// 	// this.$refs.cdxz14.init();
				// 	// 是否展示充电金额 支付方式
				// 	// this.cddxtype = true;
				// }

				//
				// this.ChargeUser = this.ChargeUser.find(e => {
				// 	return
				// })
			},
			async init14() {
				if (this.ChargeCar.type != 14 || !this.ChargeCar.gtel) {
					return;
				}

				this.init14modal();
				// if (this.$refs.ztd.activetd) {
				//   this.btntap14tdtap(this.$refs.ztd.activetd);
				// }
				// let ccplist = await this.$z.request("/Uinfoccp", {
				//   uUser: this.USearch.uUser,
				// });
				// this.ChargeUser = await this.$store.dispatch("request/getRequest", {
				//   url: "/ChargeUser",
				// });
				// let ChargeUsernogtel34 = this.ChargeUser.findIndex((e) => {
				//   return (
				//     e.gtel != this.ChargeCar.gtel && e.b_end != "1" && e.type == "34"
				//   );
				// });
				// if (ChargeUsernogtel34 != -1) {
				//   uni.showModal({
				//     title: "提示",
				//     content: "您有订单未结束，请结束后开启新订单",
				//     showCancel: false,
				//     confirmText: "马上查看",
				//     success: function (res) {
				//       if (res.confirm) {
				//         uni.navigateTo({
				//           url: "/pages/mine/GetRfCD14/GetRfCD14",
				//         });
				//       }
				//     },
				//   });
				// }

				// if (!this.USearch.ccp || this.USearch.ccp == "") {
				//   uni.showModal({
				//     title: "车辆信息完善",
				//     content:
				//       "尊敬的客户您好，为了更好的匹配您的车辆进行充电，请完善信息后再操作。",
				//     showCancel: false,
				//     confirmText: "完善信息",
				//     success: function (res) {
				//       if (res.confirm) {
				//         uni.navigateTo({
				//           url: "/pagesall/Uinfoccpedit/Uinfoccpedit",
				//         });
				//       }
				//     },
				//   });
				//   // return;
				// }
				// this.type14init = true;
			},
			ChargeCarabcallback() {
				if (
					this.ChargeCar["gtype"] == "62" ||
					this.ChargeCar["gtype"] == "63" ||
					(this.ChargeCar["type"] == "14" && this.btntext == "开始充电")
				) {
					return true;
				}
				if (this.ChargeCar["gtype"] == "2" && this.ChargeCar["gcdl5"] == "1") {
					return true;
				}
				return false;
			},
			sbzt(dqChargeCardata) {
				if (dqChargeCardata["gtype"] == "62") {
					return dqChargeCardata["gcdl" + this.zfdata.td] == "0" ? true : false;
				}
				if (dqChargeCardata.gtype == 2 && dqChargeCardata.gcdl5 == "1") {
					return dqChargeCardata["glzt" + this.zfdata.td] == 0 ? true : false;
				}

				return true;
			},
			async gcdlfn() {
				if (!this.ChargeCarabcallback()) {
					return;
				}
				let ChargeCarSys = await uni.$z.request("/ChargeCarSys", {
					gtel: this.ChargeCar.gtel,
				});
				ChargeCarSys = ChargeCarSys.length == 1 ? ChargeCarSys[0] : {};
				if (this.sbzt(ChargeCarSys)) {
					var cqtd = parseInt(this.zfdata.td) + 2;
					if (ChargeCarSys["gcdl" + cqtd] == "0") {
						this.$u.toast("设备未插枪无法充电");
						// return Promise.reject('设备未插枪无法充电');
						return;
					}
				} else {
					this.$u.toast("当前通道被占用");
					return Promise.reject("当前通道被占用");
				}
				return;
			},
			async fkfnbefore14() {
				if (this.ChargeCar.type != 14) {
					return;
				}
				if (this.btntext == "打开地锁") {
					// if (this.USearch.je >= this.mini14je) {
					// 	return
					// }
					this.$refs.chargecar14.show();
					return Promise.reject("出错了");
				}
				return;

				// return Promise.reject('出错了');
			},
		},
	};
</script>

<style>
	/* .a::before */
</style>